<template>
	<view>
		<hx-navbar ref="hxnb" :config="config">
			<block slot="right">
				<view class="edit" @tap="editName()">
					保存
				</view>
			</block>
		</hx-navbar>
		<view class="sex">
			<view class="flex justify-between align-center sex_s" v-for="(item,index) in genderType" :key="index"
				@click="genderChild(index,item.id)">
				<view class="flex align-center">
					<image :src="item.Image" style="width: 64rpx;height: 64rpx;" mode=""></image>
					<text>{{item.name}}</text>
				</view>
				<image class="select" :class="genderIndex == index ? 'selectStyle' :''"
					src="../../../static/cliend/select.png" style="width: 64rpx;height: 64rpx;" mode="">
				</image>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 标题栏配置
				config: {
					title: "修改性别",
					back: true,
					color: "#111111",
					rightSlot: true,
					backgroundColor: [1, "#FFFFFF"],
				},
				genderType: [{
						name: '男',
						id: '1',
						Image: '../../../static/cliend/boyStudent.png'
					},
					{
						name: '女',
						id: '2',
						Image: '../../../static/cliend/schoolgirl.png'
					}
				],
				userSex: '',
				genderIndex: '',
			}
		},
		onLoad(e) {
			if (e.sex == 0 || e.sex == 1) {
				this.genderIndex = 0
				this.userSex = e.sex
			} else if (e.sex == 2) {
				this.genderIndex = 1
				this.userSex = e.sex
			}
		},
		methods: {
			genderChild(e, id) {
				this.genderIndex = e
				this.userSex = id
			},
			editName() {
				let data = {
					sex: this.userSex
				}
				this.$api.deitInformation(data).then((res) => {
					if (res.statusCode == 200) {
						uni.showToast({
							title: `修改成功`,
							icon: "block",
						})
						uni.navigateBack(1)
					}
				})
			}
		}
	}
</script>

<style scoped>
	.edit {
		width: 162rpx;
		height: 70rpx;
		background: #492D22;
		border-radius: 10rpx;
		text-align: center;
		line-height: 70rpx;
		font-size: 32rpx;
		color: #ffffff;
		color: #ffffff;
		margin-right: 30rpx;
	}

	.sex {
		margin-top: 30rpx;
		background-color: #fff;
		padding: 0 30rpx;
	}

	.sex_s {
		height: 112rpx;
		line-height: 112rpx;
	}

	.sex_s:first-child {
		border-bottom: 1rpx solid rgba(30, 30, 30, 0.1);
	}

	.select {
		display: none;
	}

	.selectStyle {
		display: block;
	}
</style>
